'use strict';

module.exports = app => {
  const { INTEGER, TEXT, BOOLEAN, DATE } = app.Sequelize;

  const ThemeComment = app.model.define('theme_comment', {
    id: { type: INTEGER, primaryKey: true, autoIncrement: true },
    theme_id: INTEGER,
    user_id: INTEGER,
    content: TEXT('long'),
    oline: BOOLEAN,
    hot: BOOLEAN,
    create_time: DATE,
    update_time: DATE,
    delete_time: DATE,
  }, {
    defaultScope: {
      attributes: {
        exclude: [ 'delete_time', 'update_time' ],
      },
    },
  });

  ThemeComment.associate = function() {
    app.model.ThemeComment.belongsTo(app.model.User, {
      as: 'user',
      foreignKey: 'user_id',
      targetKey: 'id'
    });

    app.model.ThemeComment.hasMany(app.model.ThemeCommentLike, {
      as: 'like',
      foreignKey: 'them_comment_id',
      targetKey: 'id',
    });

    app.model.ThemeComment.hasMany(app.model.ThemeCommentReply, {
      as: 'reply',
      foreignKey: 'theme_comment_id',
      targetKey: 'id',
    });
  }

  return ThemeComment;
};
